Skip to content

Conversation

ada4a
Copy link
Contributor

@ada4a ada4a commented Sep 19, 2025

This PR makes the lint early-pass, and fixes the following issues:

changelog: [needless_parens_on_range_literals]: Fix FN on unsuffixed floats not ending with a .
changelog: [needless_parens_on_range_literals]: Fix FP on macro-generated code

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

r? @blyxyas

rustbot has assigned @blyxyas.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

//~^ needless_parens_on_range_literals

// lint: the macro doesn't have anything to do with the paren
let _ = 0..1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why verbatim!(0) is replaced with just 0 here, given that I use snippet_with_context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's because literal is 0 just here, which doesn't come from expansion -- the verbatim! macro takes it from its input and, well, returns it verbatim. Because of that, things like literal.span.source_callsite() don't help either. I'd appreciate some help^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run Clippy here you can check that the tokens are the same, even the syntax context (the number after the #).

So if the macro is just ($t:tt) => ($t), Clippy and the compiler overall will ignore it, plus (even worse) don't even know it's there.

That's why we cannot detect such cases, sadly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. I wanted to change the test to something like:

macro_rules! zero {
    () => {
        0
    };
}

let _ = (zero!())..1;

But I'm not even sure we want to lint that? Because it might very well be that zero! instead expanded to something like 1 - 1, in which case its output would need parenthesization (what a word). This kind of comes back to #15724 (comment), but my grammar knowledge is nowhere nearly good enough to implement something like that^^

I guess not bothering to lint this particular case is always an option as well. WDYT?

@ada4a ada4a marked this pull request as draft September 19, 2025 14:09
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 19, 2025
@ada4a ada4a marked this pull request as ready for review September 19, 2025 20:32
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 19, 2025
@blyxyas
Copy link
Member

blyxyas commented Sep 25, 2025

This PR makes the lint early-pass,

Sadly, we don't really want to make lints early unless there's a good reason. Late lint passes have better support, so we can make better utilities for them (+ they're filtered, so they don't incur any performance impact necessarily)

@ada4a
Copy link
Contributor Author

ada4a commented Sep 27, 2025

Sadly, we don't really want to make lints early unless there's a good reason. Late lint passes have better support, so we can make better utilities for them (+ they're filtered, so they don't incur any performance impact necessarily)

Huh!

Firstly, this is again something I've heard people voice the opposite opinion on12 -- though [1] in particular was made in the context of attribute-related lints, in which case late-pass is really not the right approach. I'd appreciate it if a consensus was reached on this, and ideally documented somewhere.

Also, fwiw the lint did start its life as early-pass, but was changed to late-pass during development in order to be able to detect unsuffixed float literals ending with a .3 -- but that wasn't actually necessary. And imo this lint feels a lot more natural as early-pass, because it doesn't care about types or anything.

Still, given the considerations you voiced, I could turn it back to late-pass (wouldn't be too complicated). WDYT?

Footnotes

  1. https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/attempted.20fix.20for.20disallowed_macros/near/532462418

  2. https://github.com/rust-lang/rust-clippy/pull/14986#discussion_r2384186293

  3. https://github.com/rust-lang/rust-clippy/pull/8933#issuecomment-1146679140

@rustbot

This comment has been minimized.

@ada4a ada4a force-pushed the needless_parens_on_range_literals branch from d04a02a to fc1a9ef Compare October 7, 2025 17:38
@rustbot
Copy link
Collaborator

rustbot commented Oct 7, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ada4a
Copy link
Contributor Author

ada4a commented Oct 7, 2025

Since I needed to rebase onto master anyway, I went ahead and made the lint late-pass again, and removed the problematic macro test case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants